var linetime = "";
var lineadultnum = "";
var linekidsnum = "";
var lineid = "";
var linecarid = "";
var token = "";
var contactid = "";//常用联系人id
var travellerid = "";//出游人id
var score = 0;//积分
var allscore = 0;//用户全部积分
var totalprice = 0;
var adultprice = 0;
var kidsprice = 0;
$(document).ready(function(){
	PageOnLoad();
	WantCC();
	WantCT();
	AddDeleteN();
	OrderRightNow();
	WantOrderAllP();
	WantOrderDetailInfo();
	HandWithScore();
	GoToRule();
});
//成人儿童生成结构
function AdultHtml(lineadultnum,linekidsnum){
	var a = "";
	var k = "";
	var at = "";
	for(var i=0;i<parseInt(lineadultnum);i++){
		at = "0|"  + at; 
		a = a + "<div class=\"lineorder_center_left_tour_tour_adult clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_one\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_one_item\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_one_item_up\">第"+(i+1)+"位</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_one_item_down\">成人</div>\n" +
		"</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_head clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_head_one\">*</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_head_two\">姓&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp名</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_center\">\n" +
		"<input type=\"text\" class=\"lineorder_center_left_tour_tour_adult_two_name_center_item\" placeholder=\"请与证件一致\"/>\n" +
		"</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type_one clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type_one_one\">*</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type_one_two\">证件类型</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type_two\">\n" +
		"<select name=\"type\">\n" +
		"<option value=\"身份证\">身份证</option>\n" +
		"<option value=\"出生证明\">出生证明</option>\n" +
		"</select>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type_three\">\n" +
		"<input type=\"text\" class=\"lineorder_center_left_tour_tour_adult_two_type_three_item\" placeholder=\"请输入证件号码\"/>\n" +
		"</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_head clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_head_one\">*</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_head_two\">手机号码</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_head_center\">\n" +
		"<input type=\"text\" class=\"lineorder_center_left_tour_tour_adult_two_name_head_center_item\" placeholder=\"必填，用于接收信息\"/>\n" +
		"</div>\n" +
		"</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_three\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_three_item\">清空</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_four hidden\"></div>\n" +
		"</div>";
	};
	for(var i=0;i<parseInt(linekidsnum);i++){
		at = "0|"  + at;
		k = k + "<div class=\"lineorder_center_left_tour_tour_kids clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_one\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_one_item\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_one_item_up\">第"+(i+1)+"位</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_one_item_down\">儿童</div>\n" +
		"</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_head clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_head_one\">*</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_head_two\">姓&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp名</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_name_center\">\n" +
		"<input type=\"text\" class=\"lineorder_center_left_tour_tour_adult_two_name_center_item\" placeholder=\"请与证件一致\"/>\n" +
		"</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type_one clearfix\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type_one_one\">*</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type_one_two\">证件类型</div>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type_two\">\n" +
		"<select name=\"type\">\n" +
		"<option value=\"身份证\">身份证</option>\n" +
		"<option value=\"出生证明\">出生证明</option>\n" +
		"</select>\n" +
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_two_type_three\">\n" +
		"<input type=\"text\" class=\"lineorder_center_left_tour_tour_adult_two_type_three_item\" placeholder=\"请输入证件号码\"/>\n" +
		"</div>\n" +
		"</div>\n" +
		
		"</div>\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_three\">\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_three_item\">清空</div>\n" +
		"</div>\n" +
		"\n" +
		"<div class=\"lineorder_center_left_tour_tour_adult_four hidden\"></div>\n" +
		"</div>";
	};
	var ht  = a + k;
	$("div.lineorder_center_left_tour_tour").html(ht);
	travellerid = at;
	//点击清空效果
	var clean = $("div.lineorder_center_left_tour_tour_adult_three_item");
	for(var i = 0;i<clean.length;i++){
		$("div.lineorder_center_left_tour_tour_adult_three_item:eq("+i+")").click(function(i){
			return function(){
				$("div.lineorder_center_left_tour_tour>div:eq("+i+") input").val("");
				
				//对于先选择乘客再集体清空的情况,如果用户保留了乘客对勾，再对乘客进行清理，默认乘客选择继承选择前的乘客的基本信息
			}
		}(i));
	};
}
//初始化参数及生成对应的成人儿童文本结构
function PageOnLoad(){
	token = $("text.lineorder_order_hidden_token").text();
	lineid = $("text.lineorder_order_hidden_lineid").text();
	linecarid = $("text.lineorder_order_hidden_linecarid").text();
	linetime = $("text.lineorder_order_hidden_linetime").text();
	lineadultnum = $("text.lineorder_order_hidden_adultnum").text();
	linekidsnum = $("text.lineorder_order_hidden_kidsnum").text();
	
	AdultHtml(lineadultnum,linekidsnum);
	console.log("travellerid="+travellerid);
	console.log("lineadultnum="+lineadultnum);
	console.log("linekidsnum="+linekidsnum);
	console.log("linecarid="+linecarid);
	console.log("lineid="+lineid);
	console.log("linetime="+linetime);
}
//成人儿童出游人数新增或者删除
function AddDeleteN(){
	$("div.lineorder_center_right_choose_num_adult_two:eq(0)").click(function(){
		lineadultnum --;
		if(lineadultnum < 0){
			layer.msg("人数不正确，请重试");
			
			return;
		}
		window.location.href = (basePath+"/lineorder?lineadultnum="+lineadultnum+"&linekidsnum="+linekidsnum+"&linetime="+linetime+"&linecarid="+linecarid);
//		$("div.lineorder_order_hidden_adultnum").text(lineadultnum);
//		$("div.lineorder_center_right_choose_num_adult_three").text(lineadultnum);
//		AdultHtml(lineadultnum,linekidsnum);
//		WantCT();
//		console.log("lineadultnum="+lineadultnum);
	});
	$("div.lineorder_center_right_choose_num_adult_two:eq(1)").click(function(){
		lineadultnum ++;
		window.location.href = (basePath+"/lineorder?lineadultnum="+lineadultnum+"&linekidsnum="+linekidsnum+"&linetime="+linetime+"&linecarid="+linecarid);
//		$("div.lineorder_order_hidden_adultnum").text(lineadultnum);
//		$("div.lineorder_center_right_choose_num_adult_three").text(lineadultnum);
//		AdultHtml(lineadultnum,linekidsnum);
//		WantCT();
//		console.log("lineadultnum="+lineadultnum);
	});
	$("div.lineorder_center_right_choose_num_kids_two:eq(0)").click(function(){
		linekidsnum --;
		if(linekidsnum < 0){
			layer.msg("人数不正确，请重试");
			
			return;
		}
		window.location.href = (basePath+"/lineorder?lineadultnum="+lineadultnum+"&linekidsnum="+linekidsnum+"&linetime="+linetime+"&linecarid="+linecarid);
//		$("div.lineorder_order_hidden_kidsnum").text(linekidsnum);
//		$("div.lineorder_center_right_choose_num_kids_three").text(linekidsnum);
//		AdultHtml(lineadultnum,linekidsnum);
//		WantCT();
//		console.log("linekidsnum="+linekidsnum);
	});
	$("div.lineorder_center_right_choose_num_kids_two:eq(1)").click(function(){
		linekidsnum ++;
		window.location.href = (basePath+"/lineorder?lineadultnum="+lineadultnum+"&linekidsnum="+linekidsnum+"&linetime="+linetime+"&linecarid="+linecarid);
//		$("div.lineorder_order_hidden_kidsnum").text(linekidsnum);
//		$("div.lineorder_center_right_choose_num_kids_three").text(linekidsnum);
//		AdultHtml(lineadultnum,linekidsnum);
//		WantCT();
//		console.log("linekidsnum="+linekidsnum);
	});
	
}
//初始载入请求常用联系人接口
function WantCC(){
	var token = $("text.lineorder_order_hidden_token").text();
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/lineordercontact",
		data : {
			token:token
		},		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var c = "";
			for(var i = 0;i<data.data.length;i++){
				c = c + "<div class=\"lineorder_center_left_con_choose_common_item shand\">"+data.data[i].name+"</div>"+
					"<font class=\"hidden\">"+data.data[i].contactid+"</font>"
			};
			$("div.lineorder_center_left_con_choose_common").html(c);
			ClickCCI();
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
			layer.close(LoadingIcon);
		},
	});
}
//选择常用联系人请求详细信息
function ClickCCI(){
	var l = $("div.lineorder_center_left_con_choose_common_item").length;
	for(var i =0;i<l;i++){
		$("div.lineorder_center_left_con_choose_common_item:eq("+i+")").click(function(i){
			return function(){
				$(this).addClass("lineorder_center_left_con_choose_common_itemchoose");
				$("div.lineorder_center_left_con_choose_common>div").not(this).removeClass("lineorder_center_left_con_choose_common_itemchoose");
				var id = $("div.lineorder_center_left_con_choose_common>font:eq("+i+")").text();
				 WantCCI(id);
				 console.log("id="+id);
			}
		}(i))
	}
}
//强制修改或保存出游人，获取出游人id
function WantATID(token,name,identtype,identnum,phone,contactid,begin){
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/lineordertravelinsert",
		data : {
			token:token,
			name:name,
			identtype:identtype,
			identnum:identnum,
			phone:phone,
			contactid:contactid
		},		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var id = data.data.contactid;
			$("div.lineorder_center_left_tour_tour>div:eq("+begin+")>div.lineorder_center_left_tour_tour_adult_four:eq(0)").text(id);
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
	console.log("---------------");
	console.log("token = "+token);
	console.log("name = "+name);
	console.log("identtype = "+identtype);
	console.log("identnum = "+identnum);
	console.log("phone = "+phone);
	console.log("contactid = "+contactid);
	console.log("begin = "+begin);
}
//测试是否能够提交
function TestSaveT(begin){
	var name = $("div.lineorder_center_left_tour_tour>div:eq("+begin+") input.lineorder_center_left_tour_tour_adult_two_name_center_item:eq(0)").val();
	var num = $("div.lineorder_center_left_tour_tour>div:eq("+begin+") input.lineorder_center_left_tour_tour_adult_two_type_three_item:eq(0)").val();
//	name = name.replace(/^\s+|\s+$/g,"");
//	num = num.replace(/^\s+|\s+$/g,"");//去除两头空格
	if((begin+1)<=lineadultnum){
		if(name != "" && num != ""){
			return("1");//成人符合条件
		}
	}else{
		var phone = $("div.lineorder_center_left_tour_tour:eq("+begin+") input.lineorder_center_left_tour_tour_adult_two_name_head_center_item:eq(0)").val();
//		phone = phone.replace(/^\s+|\s+$/g,"");
		if(name != "" && num != "" && phone != ""){
			return("1");//儿童符合条件
		}
	}
	return("0");//不符合条件
}
//将所有出游人强制修改或保存，组成contactid
function SaveAllT(){
	var l = $("div.lineorder_center_left_tour_tour>div");
	for(var i =0;i<l.length;i++){
		var ctid = $("div.lineorder_center_left_tour_tour>div:eq("+i+")>div.lineorder_center_left_tour_tour_adult_four:eq(0)").text();
		var name = $("div.lineorder_center_left_tour_tour>div:eq("+i+") input.lineorder_center_left_tour_tour_adult_two_name_center_item:eq(0)").val();
		var identnum = $("div.lineorder_center_left_tour_tour>div:eq("+i+") input.lineorder_center_left_tour_tour_adult_two_type_three_item:eq(0)").val();
		var identtype = $("div.lineorder_center_left_tour_tour>div:eq("+i+") select option:selected").val();
		var test = TestSaveT(i);
		if(test == "1"){
			if((i+1) <= lineadultnum){
				var phone = $("div.lineorder_center_left_tour_tour>div:eq("+i+") input.lineorder_center_left_tour_tour_adult_two_name_head_center_item:eq(0)").val();
				WantATID(token,name,identtype,identnum,phone,ctid,i);				
			}else{
				WantATID(token,name,identtype,identnum,"",ctid,i);
			}
		}else if(test == "0"){
//			alert("请将所有联系人必填信息填写完整");
			layer.msg("请将所有联系人必填信息填写完整");
		}
		
	}
}
//判断是否能够创建订单
function OrderRuleCheck(){
	var name = $("input.lineorder_center_left_con_name_two_input:eq(0)").val();
	var phone = $("input.lineorder_center_left_con_name_two_input:eq(1)").val();
	var email = $("input.lineorder_center_left_con_name_two_input:eq(2)").val();
	var message = $("input.lineorder_center_left_con_name_two_input:eq(3)").val();
	if(name == ""){
//		alert("请填写常用联系人姓名");
		layer.msg("请填写常用联系人姓名");
		return("0");
	};
	if(phone == ""){
//		alert("请填写常用联系人手机号码");
		layer.msg("请填写常用联系人手机号码");
		return("0");
	};
	var t = $("div.lineorder_center_left_tour_tour>div").length;
	var tr = "";
	for(var i =0;i<t;i++){
		var tid = $("div.lineorder_center_left_tour_tour>div:eq("+i+")>div.lineorder_center_left_tour_tour_adult_four:eq(0)").text();
		if(tid == ""){
			return("0");
		}else{
			tr = tr + "|" + tid;
		}
	};
	travellerid = tr;
	return("1");
	
}
//点击立即支付绑定事件
function OrderRightNow(){
	$("input.lineorder_order_center_order_item").click(function(){
		var loading = layer.load(1,{time:10*1000});//10秒loading，防止用户快速点击
		SaveAllT();
		window.setTimeout(CreatOrder(),2000);
	});
}
//执行创建订单操作
function CreatOrder(){
	var test = OrderRuleCheck();
	if(test == "1"){
		CreatOrderRightNow();
		return;
	};
}
//创建订单
function CreatOrderRightNow(){
	var name = $("input.lineorder_center_left_con_name_two_input:eq(0)").val();
	var phone = $("input.lineorder_center_left_con_name_two_input:eq(1)").val();
	var email = $("input.lineorder_center_left_con_name_two_input:eq(2)").val();
	var message = $("input.lineorder_center_left_con_name_two_input:eq(3)").val();
	console.log("--------------");
	console.log("订单生成参数:");
	console.log("token="+token);
	console.log("name="+name);
	console.log("phone="+phone);
	console.log("email="+email);
	console.log("message="+message);
	console.log("cid="+contactid);
	console.log("travellerid="+travellerid);
	console.log("adultnum="+lineadultnum);
	console.log("kidsnum="+linekidsnum);
	console.log("lineid="+lineid);
	console.log("linetime="+linetime);
	console.log("linecarid="+linecarid);
	console.log("score="+score);
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/lineordercreateorder",
		data : {
			token:token,
			name:name,
			phone:phone,
			email:email,
			message:message,
			cid:contactid,
			travellerid:travellerid,
			adultnum:lineadultnum,
			kidsnum:linekidsnum,
			lineid:lineid,
			linetime:linetime,
			linecarid:linecarid,
			score:score
		},		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			
			var lineorderid = data.data.orderid;
			var x = $("div.lineorder_center_left_tour_tour input");
			for(var i =0;i<x.length;i++){
				var person = $("div.lineorder_center_left_tour_tour input:eq(i)").val()
				if(person == ""){
					layer.msg("请填写完整出游人信息");
					return;
				};
			}
			window.location.href = (basePath+"/linepay?lineorderid="+lineorderid);
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
	
}
//选择请求常用联系人信息接口
function WantCCI(id){
	LoadingIcon = layer.load();
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/lineordercontactinfo",
		data : {
			id:id
		},		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var name = data.data[0].name;
			var phone = data.data[0].phone;
			var email = data.data[0].email;
			contactid = data.data[0].contactid;
			$("input.lineorder_center_left_con_name_two_input:eq(0)").val(name);
			$("input.lineorder_center_left_con_name_two_input:eq(1)").val(phone);
			$("input.lineorder_center_left_con_name_two_input:eq(2)").val(email);
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
			layer.close(LoadingIcon);
		},
	});
}
//请求常用出游人信息
function WantCT(){
	var token = $("text.lineorder_order_hidden_token").text();
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/lineordertravellist",
		data : {
			token:token
		},		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var t = "";
			for(var i = 0;i<data.data.length;i++){
				t = t + "<input type=\"checkbox\" class=\"lineorder_center_left_tour_choose_center_item\" value="+data.data[i].id+" />"+
								"<font class=\"hidden\">"+data.data[i].name+"</font>"+
								"<font class=\"hidden\"></font>"
			}
			$("div.lineorder_center_left_tour_choose_center").html(t);
			ChooseCT();
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//寻找可用begin
function SearchBegin(){
	var l = $("div.lineorder_center_left_tour_tour>div").length;
	for(var i =0;i<l;i++){
		var name = $("div.lineorder_center_left_tour_tour>div:eq("+i+") input.lineorder_center_left_tour_tour_adult_two_name_center_item:eq(0)").val();
		var identnum = $("div.lineorder_center_left_tour_tour>div:eq("+i+") input.lineorder_center_left_tour_tour_adult_two_type_three_item:eq(0)").val();
		var phone  = $("div.lineorder_center_left_tour_tour>div:eq("+i+") input.lineorder_center_left_tour_tour_adult_two_name_head_center_item:eq(0)").val();
		if(phone != null){
			if(name == "" && identnum == "" && phone == ""){			
				return(i)
			}
		}else{
			if(name == "" && identnum == ""){			
				return(i)
			}
		}		
	};	
	return(-1);
}
//选中常用出游人绑定事件
function ChooseCT(){
	var l = $("div.lineorder_center_left_tour_choose_center>input").length;
	for(var i =0;i<l;i++){
		$("div.lineorder_center_left_tour_choose_center>input:eq("+i+")").click(function(i){
			return function(){
				var text = $("div.lineorder_center_left_tour_choose_center>font.hidden:eq("+i+")").text();
				if(text == ""){
					
					var id = $("div.lineorder_center_left_tour_choose_center>input:eq("+i+")").val();
					var begin = SearchBegin();
					console.log("id="+id);
					console.log("begin="+begin);
					if(begin != -1){
						WantCTI(id,begin);
						$("div.lineorder_center_left_tour_choose_center>font.hidden:eq("+i+")").text(begin);//将可更改的位置做标记
					}else{
//						alert("无可使用位置");
						layer.msg("无可使用位置");
						$("div.lineorder_center_left_tour_choose_center>font.hidden:eq("+i+")").text(begin);//将可更改的位置做标记
					}					
				}else{
					$("div.lineorder_center_left_tour_tour>div:eq("+text+") input.lineorder_center_left_tour_tour_adult_two_name_center_item:eq(0)").val("");
					$("div.lineorder_center_left_tour_tour>div:eq("+text+") input.lineorder_center_left_tour_tour_adult_two_type_three_item:eq(0)").val("");
					$("div.lineorder_center_left_tour_tour>div:eq("+text+") input.lineorder_center_left_tour_tour_adult_two_name_head_center_item:eq(0)").val("");
					$("div.lineorder_center_left_tour_choose_center>font.hidden:eq("+i+")").text("");
					$("div.lineorder_center_left_tour_tour>div:eq("+text+") div.lineorder_center_left_tour_tour_adult_four:eq(0)").text("");
				}				
			}
		}(i));
	};
}
//请求常用出游人信息
function WantCTI(id,begin){
	var loadshow = layer.load();
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/lineordertravellistinfo",
		data : {
			id:id
		},		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var b = begin;
			var name = data.data[0].name;
			var identtype = data.data[0].identtype;
			var identnum = data.data[0].identnum;
			var phone = data.data[0].phone;
			var id = data.data[0].id;
			if((b+1)<=lineadultnum){
//				成人操作
				$("div.lineorder_center_left_tour_tour>div:eq("+b+") input.lineorder_center_left_tour_tour_adult_two_name_center_item:eq(0)").val(name);
				$("div.lineorder_center_left_tour_tour>div:eq("+b+") input.lineorder_center_left_tour_tour_adult_two_type_three_item:eq(0)").val(identnum);
				$("div.lineorder_center_left_tour_tour>div:eq("+b+") input.lineorder_center_left_tour_tour_adult_two_name_head_center_item:eq(0)").val(phone);
				$("div.lineorder_center_left_tour_tour>div:eq("+b+") div.lineorder_center_left_tour_tour_adult_four:eq(0)").text(id);
			}else{
//				儿童操作
				$("div.lineorder_center_left_tour_tour>div:eq("+b+") input.lineorder_center_left_tour_tour_adult_two_name_center_item:eq(0)").val(name);
				$("div.lineorder_center_left_tour_tour>div:eq("+b+") input.lineorder_center_left_tour_tour_adult_two_type_three_item:eq(0)").val(identnum);
				$("div.lineorder_center_left_tour_tour>div:eq("+b+") div.lineorder_center_left_tour_tour_adult_four:eq(0)").text(id);
			}
			if(identtype == "出生证明"){
				$("div.lineorder_center_left_tour_tour>div:eq("+b+") select:eq(0)").val("出生证明");
			}else{
				$("div.lineorder_center_left_tour_tour>div:eq("+b+") select:eq(0)").val("身份证");
			}
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
			layer.close(loadshow);
		},
	});
}
//请求没用积分抵扣的订单总价格
function WantOrderAllP(){
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/lineorderpriceall",
		data : {
			linecarid:linecarid,
			linetime:linetime
		},		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var a = data.data.adultprice;
			var k = data.data.kidspirce;
			var adultprice = a * lineadultnum;
			var kidsprice = k * linekidsnum;
			var allprice = adultprice + kidsprice;
			totalprice = adultprice + kidsprice;
			$("div.lineorder_center_right_price_content_adult_right_price:eq(0)").text(adultprice);
			$("div.lineorder_center_right_price_content_adult_right_price:eq(1)").text(kidsprice);
			//先假设用户没有积分
			$("div.lineorder_center_right_price_content_adult_right_price:eq(2)").text("0");
			$("div.lineorder_order_center_price_one").text(allprice);
			//只有知道了总价格才能对积分进行操作
			WantUserScore();
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//请求订单页详情信息
var WantOrderDetailInfo = function(){
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/lineinfobaseinfo",
		data : {
			lineid:lineid,
		},		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var title = data.data.title;
			var codenum = data.data.codenum;
			var city = data.data.city;
			$("div.lineorder_center_right_title_one").text(title);
			$("div.lineorder_center_right_title_two_center").text(codenum);
			$("div.lineorder_center_right_choose_city_two").text(city);
			//设置title
			$(document).attr("title","订单填写_"+title);//修改title值  
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//请求个人的积分详情
var WantUserScore = function(){
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/car/rentorderscore",
		data : {
			token:token,
		},		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			allscore = data.data.score;
			console.log("allscore="+allscore);
			FirstHandWithScore();
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//首次对积分操作
var FirstHandWithScore = function(){
	var scoreCount = allscore * 0.01;
	var cscore = 0;
	if(scoreCount >= totalprice){
		if(totalprice >= 1000){
				
				if($("input#useScore").is(":checked")){//检查是否选中使用积分
					cscore = 100000;
					score = allscore;
				}else{
					cscore = 0;
					score = 0;
				};			
//				var wordOne = "使用积分抵用"+ 1000 +"元";
				var wordTwo = "当前积分" + allscore + "可用积分" + 100000;
//				$("div.rentorder_down_two_item_two_score_up").text(wordOne);
				$("div.lineorder_center_right_price_less_word").text(wordTwo);
				var showprice = totalprice - cscore*0.01;
				$("div.lineorder_order_center_price_one").text(showprice);
				var showscorecount = cscore * 0.01;
				$("div.lineorder_center_right_price_content_adult_right_price:eq(2)").text(showscorecount);
				console.log("fone");
		}else if(totalprice < 1000){
			
				if($("input#useScore").is(":checked")){
					cscore = totalprice * 100;
					score = allscore;
				}else{
					cscore = 0;
					score = 0;
				};
//				var wordOne = "使用积分抵用" + totalprice + "元";
				var wordTwo = "当前积分" + allscore + "可用积分" + totalprice * 100;
//				$("div.rentorder_down_two_item_two_score_up").text(wordOne);
				$("div.lineorder_center_right_price_less_word").text(wordTwo);
				var showprice = totalprice - cscore*0.01;
				$("div.lineorder_order_center_price_one").text(showprice);
				var showscorecount = cscore * 0.01;
				$("div.lineorder_center_right_price_content_adult_right_price:eq(2)").text(showscorecount);
				console.log("ftwo");
		};
		
	}else if(scoreCount < totalprice){
		if(scoreCount >= 1000){
			
				if($("input#useScore").is(":checked")){
					cscore = 100000;
					score = allscore;
				}else{
					cscore = 0;
					score = 0;
				};
//				var wordOne = "使用积分抵用" + 1000 + "元";
				var wordTwo = "当前积分" + allscore + "可用积分" + 100000;
//				$("div.rentorder_down_two_item_two_score_up").text(wordOne);
				$("div.lineorder_center_right_price_less_word").text(wordTwo);
				var showprice = totalprice - cscore*0.01;
				$("div.lineorder_order_center_price_one").text(showprice);
				var showscorecount = cscore * 0.01;
				$("div.lineorder_center_right_price_content_adult_right_price:eq(2)").text(showscorecount);
				console.log("fthree");
		}else if(scoreCount < 1000){
			
				if($("input#useScore").is(":checked")){
					cscore = allscore;
					score = allscore;
				}else{
					cscore = 0;
					score = 0;
				};
//				var wordOne = "使用积分抵用" + allscore*0.01 + "元";
				var wordTwo = "当前积分" + allscore + "可用积分" + allscore;
//				$("div.rentorder_down_two_item_two_score_up").text(wordOne);
				$("div.lineorder_center_right_price_less_word").text(wordTwo);
				var showprice = totalprice - cscore*0.01;
				$("div.lineorder_order_center_price_one").text(showprice);
				var showscorecount = cscore * 0.01;
				$("div.lineorder_center_right_price_content_adult_right_price:eq(2)").text(showscorecount);
				console.log("ffour");
		};
	};
	console.log("score="+score);
	console.log("allscore="+allscore);
	console.log("totalprice="+totalprice);
}
//对积分进行操作
var HandWithScore = function(){
	$("input#useScore").click(function(){
		FirstHandWithScore();
	});
}
//点击预定须知新开页面
var GoToRule = function(){
	$("div.lineorder_order_center_know_know").click(function(){
		window.open(basePath+"/lineservicerule"); 
	});
}